package com.yadang.stream;

import com.yadang.java8.entity.Employee;
import com.yadang.java8.entity.EmployeeData;
import com.yadang.java8.entity.MyEmployee;
import org.junit.Test;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * @author: 亚当
 * @date: 2023年02月22日 20:28
 * @package: com.yadang.stream
 * @Description: TODO
 */
public class StreamAPITest1 {
    @Test
    public void test(){
        List<MyEmployee> list = EmployeeData.getEmployees();
        Stream<MyEmployee> stream = list.stream();
        stream.filter(new Predicate<MyEmployee>() {
            @Override
            public boolean test(MyEmployee myEmployee) {
                return false;
            }
        });
    }
    @Test
    public void test1(){
        List<MyEmployee> list = EmployeeData.getEmployees();
        Stream<MyEmployee> stream = list.stream();
        stream.filter(e -> e.getSalary() > 7000).forEach(System.out::println);

        System.out.println("----------------------");
        list.stream().limit(3).forEach(System.out::println);

        System.out.println("----------------------");
        list.stream().skip(3).forEach(System.out::println);

        System.out.println("----------------------");
        list.add(new MyEmployee(1000,"董总",40,5000));
        list.add(new MyEmployee(1000,"董总",40,5000));
        list.add(new MyEmployee(1000,"董总",40,5000));
        list.add(new MyEmployee(1000,"董总",40,5000));

        list.stream().distinct().forEach(System.out::println);
    }
    @Test
    public void test2(){
        List<String> list = Arrays.asList("AA", "BB", "CC", "DD");
        list.stream().map(str -> str.toLowerCase()).forEach(System.out::println);

        System.out.println("------------------");
        List<MyEmployee> employees = EmployeeData.getEmployees();
        Stream<String> nameStream = employees.stream().map(MyEmployee::getName);
        nameStream.filter(name -> name.length() > 3).forEach(System.out::println);
    }
    @Test
    public void test3(){
        List list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        List list2 = new ArrayList<>();
        list2.add(9);
        list2.add(8);
        list2.add(7);
        //list.add(list2);
        System.out.println(list);
        list.addAll(list2);
        System.out.println(list);
    }
    // 排序
    @Test
    public void test5(){
        List<Integer> list = Arrays.asList(12, 34, 56, 32, 8, 98);
        list.stream().sorted().forEach(System.out::println);

        List<MyEmployee> employees = EmployeeData.getEmployees();
        employees.stream().sorted((e1,e2) ->{
            return Integer.compare(e1.getAge(),e2.getAge());
        }).forEach(System.out::println);
    }
}
